<script setup lang="ts">
import type { DialogModel, PtRecord } from '@/index.d';
const dialogModel = defineModel<DialogModel<PtRecord>>('dialogModel', {
  required: true
});

const getNdeMethod = (method: string) => {
  switch (method.toLowerCase()) {
    case 'pt':
      return '渗透检测记录';
    case 'mt':
      return '磁粉检测记录';
    case 'ut':
      return '超声检测记录';
    case 'rt':
      return '射线检测记录';
    case 'ch':
      return '超声测厚记录';
  }
};

const dialogTitle = computed(() => {
  const ndeMethod = getNdeMethod(dialogModel.value.title);
  switch (dialogModel.value.type) {
    case 'view':
      return `查看${ndeMethod}`;
    case 'insert':
      return `新增${ndeMethod}`;
    case 'update':
      return `修改${ndeMethod}`;
  }
});

const emit = defineEmits<{
  (e: 'save'): void;
  (e: 'submit'): void;
}>();
</script>
<template>
  <el-dialog
    v-model="dialogModel.visible"
    destroy-on-close
    :close-on-press-escape="false"
    fullscreen
  >
    <template #header>
      {{ dialogTitle }}
    </template>
    <template #default>
      <el-scrollbar>
        <el-space fill wrap>
          <slot></slot>
        </el-space>
      </el-scrollbar>
    </template>
    <template #footer>
      <el-button type="success" @click="emit('submit')" v-if="dialogModel.type !== 'view'">
        保存
      </el-button>
      <el-button type="danger" @click="dialogModel.visible = false"> 关闭 </el-button>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>
.el-dialog {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 100%;
  margin: 0;
  color: red;
  .el-scrollbar {
    // height: calc(100vh - 128px);
    .el-space {
      width: 100%;
    }
  }
}
</style>
